#ifndef OPERATORTABLE_H
#define OPERATORTABLE_H

#include <memory>
#include <functional>
#include <cmath>
#include "Platform.h"

class OperatorTable
{
/**
 * 单例
 */
private:
    inline static std::shared_ptr<OperatorTable> instance = nullptr;
public:
    static inline std::shared_ptr<OperatorTable> Instance()
    {
        if(nullptr == instance)
            instance = std::shared_ptr<OperatorTable>(new OperatorTable);
        return instance;
    }

public:

    using Priority = uint8_t;
    static const Priority PriorityMax = UINT8_MAX;
    struct OperatorInfo
    {
        Priority priority;
        std::function<double(double, double )> active;
    };
    inline const pLib::map<char, OperatorInfo>& GetTable() const { return table; }
private:
    OperatorTable()
    {
        table['+'] = {1, [](double d1, double d2)->double { return d1 + d2; }};
        table['-'] = {1, [](double d1, double d2)->double { return d1 - d2; }};
        table['*'] = {2, [](double d1, double d2)->double { return d1 * d2; }};
        table['/'] = {2, [](double d1, double d2)->double { return d1 / d2; }};
        table['^'] = {2, [](double d1, double d2)->double { return pow(d1, d2); }};
    }
    pLib::map<char, OperatorInfo> table;
};


#endif //OPERATORTABLE_H
